package com.qf.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {
    @Bean
    public Queue helloQueue(){
        return new Queue("helloQueue");
    }
    @Bean
    public Queue userQueue(){
        return new Queue("user");
    }
    /*-------验证topic Exchange的队列-------*/
    @Bean
    public Queue queueMessage(){
        return new Queue("topic.message");
    }
    @Bean
    public Queue queueMessages(){
        return new Queue("topic.messages");
    }
    /*---------验证fanout Exchange的队列----------*/
    @Bean
    public Queue  AMessage(){
        return new Queue("fanout.A");
    }
    @Bean
    public Queue BMessage(){
        return new Queue("fanout.B");
    }
    @Bean
    public Queue CMessage(){
        return new Queue("fanout.C");
    }
    @Bean
    public TopicExchange exchange(){
        return new TopicExchange("exchange");
    }
    @Bean
    public FanoutExchange fanoutExchange(){
        return new FanoutExchange("fanoutExchange");
    }

    /**
     * 将队列topic.message与exchange绑定，bingding_key为topic.message，就是完全匹配
     * @param queueMessage
     * @param exchange
     * @return
     */
    @Bean
    public Binding bindingExchangeMessage(Queue queueMessage,TopicExchange exchange){
        return BindingBuilder.bind(queueMessage).to(exchange).with("topic.message");
    }

    /**
     * 将队列topic.messages与exchange绑定，binding_key为topic.#,模糊匹配
     * @param queueMessage
     * @param exchange
     * @return
     */
    @Bean
    public Binding bindingExchangeMessages(Queue queueMessage,TopicExchange exchange){
        return BindingBuilder.bind(queueMessage).to(exchange).with("topic.#");
    }

    @Bean
    public Binding  bindingExchangeA(Queue AMessage ,FanoutExchange fanoutExchange){
        return BindingBuilder.bind(AMessage).to(fanoutExchange);
    }
    @Bean
    public Binding bindingExchangeB(Queue BMessage ,FanoutExchange fanoutExchange){
        return BindingBuilder.bind(BMessage).to(fanoutExchange);
    }
    @Bean
    public Binding bindingExchange(Queue CMessage ,FanoutExchange fanoutExchange){
        return BindingBuilder.bind(CMessage).to(fanoutExchange);
    }
}